package com.cal.calonecal.controller;

import com.cal.calonecal.common.Response;
import com.cal.calonecal.pojo.dto.CreateExamDTO;
import com.cal.calonecal.pojo.dto.ExamSubmitDTO;
import com.cal.calonecal.pojo.vo.EquationVO;
import com.cal.calonecal.pojo.vo.ExamVO;
import com.cal.calonecal.pojo.vo.JudgeResultVO;
import com.cal.calonecal.pojo.vo.UserProblemVO;
import com.cal.calonecal.service.IExamService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * @author 76004
 * @apiNote
 * @date 2023/5/12 15:02
 */
@RestController
@RequestMapping("/problemmm")
@CrossOrigin
public class ExamController {
    @Autowired
    private IExamService problemService;

    @PostMapping("/judge")
    public CompletableFuture<Response<JudgeResultVO>>judge(@RequestBody ExamSubmitDTO problemSubmitDTO){
        return problemService.judge(problemSubmitDTO);
    }

    /***
     * 老师才能create
     * @param createExamDTO
     * @return
     */
    @PostMapping("/create-exam")
    public Response<ExamVO> createExam(@RequestBody CreateExamDTO createExamDTO) {
        return problemService.createExam(createExamDTO);
    }

    @GetMapping("/get-user-problem")
    public Response<List<UserProblemVO>> getUserProblem(HttpServletRequest httpServletRequest){
        return problemService.getUserProblem(httpServletRequest);
    }

    @GetMapping("/download")
    @ApiModelProperty(value = "根据试卷id打包下载excel文件")
    public void downloadExamPaper (HttpServletResponse response, @RequestParam Long examId){
        problemService.download(response, Math.toIntExact(examId));
    }


    @GetMapping("/start-exam")
    public Response<List<EquationVO>> startExam(Long eid, HttpServletRequest httpServletRequest){
        return problemService.startExam(eid, httpServletRequest);
    }

    @GetMapping("/signup")
    public Response<Void>signup(Long eid, HttpServletRequest httpServletRequest){
        return problemService.signUp(eid, httpServletRequest);
    }

    @GetMapping("/get-exam-list")
    public Response<List<ExamVO>>getExamList(Integer pageNum, Integer pageSize, Long classId){
        return problemService.getExamList(pageNum, pageSize, classId);
    }
}
